package www.openteam.com.ui.prdctnMngmnt;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import www.openteam.com.R;
import www.openteam.com.adapter.PrdctnMngmnt.SendRCKSearchAdp;
import www.openteam.com.base.mBaseFragment;
import www.openteam.com.bean.OutFactoryMsg;
import www.openteam.com.contract.PrdctnMngmnt.SendRCKSearchContract;
import www.openteam.com.presenter.prdctnMngmnt.SendRCKSearchPrst;
import www.openteam.com.tool.ToastUtil;


public class SendRCKSearchFragment extends mBaseFragment<SendRCKSearchPrst> implements SendRCKSearchContract.SendRECKSearchView {


    @Bind(R.id.SRCKSearch_recyclerview)
    RecyclerView SRCKSearchRecyclerview;
//    @Bind(R.id.et_search)
    EditText etSearch;
//    @Bind(R.id.iv_search)
    ImageView ivSearch;

    private SendRCKSearchAdp sendRCKSearchAdp;
    RCKSCallback rcksCallback;

    public SendRCKSearchFragment() {
        // Required empty public constructor
    }


    public interface RCKSCallback {
        void postdata(OutFactoryMsg.DataBeanX.DataBean dataBean);
    }

    public void setRcksCallback(RCKSCallback rcksCallback) {
        this.rcksCallback = rcksCallback;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_send_rcksearch, container, false);
        ivSearch = (ImageView) view.findViewById(R.id.iv_search);
        etSearch = (EditText) view.findViewById(R.id.et_search);
//        initRView(view);
//        mRecyclerView.addOnScrollListener(mOnScrollListener);
        ButterKnife.bind(this, view);
        SRCKSearchRecyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
        mPresenter = loadPresenter();
        initView();
        initData();
        initListener();
        return view;
    }

    @Override
    protected void initData() {
        if (mPresenter != null)
            mPresenter.attachView(this);
    }

//    @OnClick(R.id.iv_search)
//    public void onViewClicked() {
//        mPresenter.findOutFactoryMsg();
//    }

    @Override
    protected void initListener() {
        ivSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.findOutFactoryMsg();
            }
        });
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void otherViewClick(View view) {

    }

    @Override
    protected SendRCKSearchPrst loadPresenter() {
        return new SendRCKSearchPrst();
    }


    @Override
    public void onRefresh() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void findOutFactoryMsg(OutFactoryMsg outFactoryMsg) {
        if (null == sendRCKSearchAdp) {
            sendRCKSearchAdp = new SendRCKSearchAdp(getContext(), outFactoryMsg.getData().getData());
        }
        SRCKSearchRecyclerview.setAdapter(sendRCKSearchAdp);
        sendRCKSearchAdp.setSendRCKSearchClickBack(new SendRCKSearchAdp.SendRCKSearchClickBack() {
            @Override
            public void postdata(OutFactoryMsg.DataBeanX.DataBean dataBean) {
                if (rcksCallback != null) {
                    rcksCallback.postdata(dataBean);
                }
            }
        });
    }

    @Override
    public void findOutFactoryMsgfail(String msg) {
        ToastUtil.showToast(getContext(), msg);
    }
}
